/* Helper methods for the Date/Time Selector compnent 

    FIXME: This needs to be done server side!
*/

function intPad( num, width )
{
    var s = num.toString();
    while( s.length < width )
        s = "0" + s;
        
    return s;        
}

function updateDatetimeComponent( identity )
{

    var year  = document.getElementsByName( identity + "_year"  )[0].value;
    var month = document.getElementsByName( identity + "_month" )[0].value;
    var day   = document.getElementsByName( identity + "_day"   )[0].value;
    
    var hiddenField = document.getElementById( identity );

    
    if(!( year && month && day )) 
    {
        hiddenField.value = "";
        return;
    }
    
    dateString = year + "-" + month + "-" + day;
    
    try{
        var hour   = document.getElementsByName( identity + "_hour"   )[0].value;
        var minute = document.getElementsByName( identity + "_minute"   )[0].value;
        
        if( hour && minute ) dateString += " " + intPad(hour,2) + ":" + intPad(minute,2);
        
    }
    catch(e){}        
    
    hiddenField.value = dateString;    
    
}